#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "sortlib.h"
#include "timelib.h"

#define MAXNUM	10000

int mycomp(const void *a, const void *b)
{
	int *_a = (int *)a;
	int *_b = (int *)b;

	if(*_a > *_b)
		return 1;
	else if(*_a < *_b)
		return -1;
	else
		return 0;
}

int main()
{
	int i, j;
	int *num = (int *)calloc(MAXNUM, sizeof(int));

	srand(time(NULL));

	for(i = 0; i < MAXNUM; i++)
	{
		num[i] = rand() % MAXNUM;
	}
	time_line_start(0);
	qsort(num, MAXNUM, sizeof(int), mycomp); //system
	time_line_end("qsort", 0);
	// 7ms

	for(i = 0; i < MAXNUM; i++)
	{
		num[i] = rand() % MAXNUM;
	}
	time_line_start(1);
	cel_insertion_sort(num, MAXNUM, sizeof(int), mycomp);
	time_line_end("insert", 1);
	// 700ms

	for(i = 0; i < MAXNUM; i++)
	{
		num[i] = rand() % MAXNUM;
	}
	time_line_start(2);
	cel_shell_sort(num, MAXNUM, sizeof(int), mycomp);
	time_line_end("shell", 2);
	// 9ms

	for(i = 0; i < MAXNUM; i++)
	{
		num[i] = rand() % MAXNUM;
	}
	time_line_start(3);
	cel_merge_sort(num, MAXNUM, sizeof(int), mycomp);
	time_line_end("merge", 3);
	// 9ms

	for(i = 0; i < MAXNUM; i++)
	{
		num[i] = rand() % MAXNUM;
	}
	time_line_start(4);
	cel_quick_sort(num, MAXNUM, sizeof(int), mycomp);
	time_line_end("quick", 4);
	// 4ms

#if 0
	for(i = 0; i < MAXNUM; i++)
	{
		printf("%4d ", num[i]);
		if(i % 20 == 19)
			printf("\n");
	}
	printf("\n");
#endif
	/* 推荐先使用希尔排序，如果不理想再使用快速排序 */
	return 0;
}
